package com.eps.tesoreria.DAO;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.stereotype.Repository;

import com.eps.tesoreria.Entity.ComprobanteCaja;



@Repository
public class LiquidacionCobranzaJdbcDAO {

	@Resource(name = "SQLDataSource")
	DataSource dsAdministracion;
	
	public String getIdComprobanteCaja(ComprobanteCaja comprobante) throws Exception {
        String retorno = null;
        Connection cnx = null;
        try {
            //Utiles_Fecha fecha = new Utiles_Fecha(orden.getFechaemision());
            cnx = this.dsAdministracion.getConnection();
            CallableStatement csLlamada = cnx.prepareCall("{? = call [dbo].[f_teso_getcodigoComprobanteCaja](?,?,?)}");
            csLlamada.registerOutParameter(1, 12);
            csLlamada.setString(2, comprobante.getTipoComprobante().getIdentificadorSerie());
            csLlamada.setString(3, comprobante.getAnio());
            csLlamada.setString(4, comprobante.getMes());
            csLlamada.execute();
            retorno = csLlamada.getString(1);
        } catch (SQLException ex) {
            throw ex;
        } finally {
            try {
                cnx.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return retorno;
    }

}
